package com.edu.controller;

import com.edu.dao.IndexDao;


import com.edu.data.News;
import com.edu.data.Product;
import com.edu.data.ProductCategory;
import com.edu.data.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/index")
public class IndexController {
    @Autowired
    IndexDao dao;
    // DaoImpl dao;

    @RequestMapping("/indexs")
    public String indexDetail(Model model) throws IOException, SQLException {
        List<News> newsList = dao.getnews();
        model.addAttribute("allNews",newsList);
        List<Product> productList = dao.getAllProduct();
        model.addAttribute("products",productList);
        List<ProductCategory> productCategoryList = dao.getAllProductCategory();
        model.addAttribute("categories",productCategoryList);
        return "index";
    }

    @RequestMapping("/leffts")
    public String indexDetail(Model model, int id) throws IOException, SQLException {
        List<News> newsList = dao.getnews();
        model.addAttribute("allNews",newsList);
        List<Product> productList = dao.getClassProduct(id);
        model.addAttribute("products",productList);
        List<ProductCategory> productCategoryList = dao.getAllProductCategory();
        model.addAttribute("categories",productCategoryList);
        return "index";
    }
}




